package com.lecture.java8.date;

public class Demo2 {

    public static void main(String[] args) {
        int x = 0; // 获取要检查的值
        ValueChecker checker = ValueChecker.check(x);
        if (checker.greaterThan(1).greaterThan(2).greaterThan(3) != null) {
            String condition = checker.getCondition();
            System.out.println(condition+"  ");
        }
    }
}



class ValueChecker {
    private final int value;
    private String condition;

    private boolean passed;

    private ValueChecker(int value) {
        this.value = value;
        this.passed = true;
    }

    public static ValueChecker check(int value) {
        return new ValueChecker(value);
    }

    public ValueChecker greaterThan(int threshold) {
        if (passed && value > threshold) {
            condition = "Value is greater than " + threshold;
            return this;
        } else {
            passed = false;
            return this;
        }
    }

    public String getCondition() {
        return condition;
    }
}